﻿@{
    ViewBag.Title = "QUnit Example";
    Layout = "~/Views/Shared/_Layout.Test.cshtml";
}

@CoffeeScripts.Render("~/CoffeeScripts/shared/coffee")       
@CoffeeScripts.Render("~/CoffeeScripts/models/coffee")
@CoffeeScripts.Render("~/CoffeeScripts/controllers/coffee")
<script type="text/coffeescript">
_file1path = "/CoffeeScripts/tests/data/json/1.txt";
_arch1path = "/CoffeeScripts/tests/data/json/3.txt";
_dir1path = "/CoffeeScripts/tests/data/json/2.txt";
_elist1path = "/CoffeeScripts/tests/data/json/list.txt";
_elist1page1path = "/CoffeeScripts/tests/data/json/listPage1.txt";
_elist1page2path = "/CoffeeScripts/tests/data/json/listPage2.txt";

asyncTest( "Parse entry list from JSON", () ->  
  $.getJSON(_elist1path)
  .success((xhr, s, e) =>
        ok(xhr != null, "_elist1path is null")        
        _elist1 = Cofe.EntryList.fromJson(xhr)
        console.log(_elist1)
        ok(_elist1 != undefined, "Entrylist not created.")
        ok(_elist1.entries.length == 24, "Entry parse error.")        
        start()
      )
  .error((xhr, s, e) => 
        ok(false, "_elist1path - " + e)
        start()
      )  
  )

asyncTest( "Parse paginate entry list from JSON", () ->  
  $.getJSON(_elist1page1path)
  .success((xhr, s, e) =>
        ok(xhr != null, "_elist1page1path is null")        
        _elist2 = Cofe.EntryList.fromJson(xhr)
        console.log(_elist2)
        ok(_elist2 != undefined, "Entrylist not created.")
        ok(_elist2.entries.length == 5, "Entry parse error, wrong entry number.")        
        ok(_elist2.links.prev == undefined, "First page so prev shouldnt be defined.")
        ok(_elist2.links.self != undefined , "Cannot find self page.")
        ok(_elist2.links.self.url ==  _elist1page1path, "Self link unmatched.")
        ok(_elist2.links.next != undefined , "Cannot find next page.")
        ok(_elist2.links.next.url ==  _elist1page2path, "Next link unmatched.")
        start()
      )
  .error((xhr, s, e) =>         
        ok(false, "_elist1page1path - " + e)
        start()
      )  
  )



</script>

